home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / hplip / ui / devmgr4.py < prev    next >
Encoding:
Python Source  |  2007-04-04  |  47.3 KB  |  1,262 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2007 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Authors: Don Welch, Pete Parks
  20. #
  21.  
  22. from __future__ import generators
  23.  
  24. # Std Lib
  25. import sys, time, os, gzip
  26.  
  27. # Local
  28. from base.g import *
  29. from base import device, utils, service
  30. from prnt import cups
  31. from base.codes import *
  32.  
  33. # Qt
  34. from qt import *
  35.  
  36. # Main form
  37. from devmgr4_base import DevMgr4_base
  38.  
  39. # Scrollviews
  40. from scrollview import ScrollView
  41. from scrollfunc import ScrollFunctionsView
  42. from scrollstatus import ScrollStatusView
  43. from scrollprintsettings import ScrollPrintSettingsView
  44. from scrollprintcontrol import ScrollPrintJobView
  45. from scrolltool import ScrollToolView, ScrollDeviceInfoView, ScrollTestpageView, ScrollPrinterInfoView
  46. from scrollsupplies import ScrollSuppliesView
  47. from scrollprint import ScrollPrintView
  48. from scrollfax import ScrollFaxView
  49.  
  50. # Misc forms
  51. from nodevicesform import NoDevicesForm
  52. from settingsdialog import SettingsDialog
  53. from aboutdlg import AboutDlg
  54.  
  55. # all in seconds
  56. MIN_AUTO_REFRESH_RATE = 5
  57. MAX_AUTO_REFRESH_RATE = 60
  58. DEF_AUTO_REFRESH_RATE = 30
  59.  
  60.  
  61. class IconViewItem(QIconViewItem):
  62.     def __init__(self, parent, text, pixmap, device_uri, is_avail=True):
  63.         QIconViewItem.__init__(self, parent, text, pixmap)
  64.         self.device_uri = device_uri
  65.         self.is_avail = is_avail
  66.         
  67.         
  68. class PasswordDialog(QDialog):
  69.     def __init__(self,prompt, parent = None,name = None,modal = 0,fl = 0):
  70.         QDialog.__init__(self,parent,name,modal,fl)
  71.         
  72.         if not name:
  73.             self.setName("PasswordDialog")
  74.  
  75.         passwordDlg_baseLayout = QGridLayout(self,1,1,11,6,"passwordDlg_baseLayout")
  76.  
  77.         self.passwordLineEdit = QLineEdit(self,"passwordLineEdit")
  78.         self.passwordLineEdit.setEchoMode(QLineEdit.Password)
  79.  
  80.         passwordDlg_baseLayout.addMultiCellWidget(self.passwordLineEdit,1,1,0,1)
  81.  
  82.         self.promptTextLabel = QLabel(self,"promptTextLabel")
  83.  
  84.         passwordDlg_baseLayout.addMultiCellWidget(self.promptTextLabel,0,0,0,1)
  85.         spacer1 = QSpacerItem(20,61,QSizePolicy.Minimum,QSizePolicy.Expanding)
  86.         passwordDlg_baseLayout.addItem(spacer1,2,0)
  87.         spacer2 = QSpacerItem(321,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  88.         passwordDlg_baseLayout.addItem(spacer2,3,0)
  89.  
  90.         self.okPushButton = QPushButton(self,"okPushButton")
  91.  
  92.         passwordDlg_baseLayout.addWidget(self.okPushButton,3,1)
  93.  
  94.         self.languageChange()
  95.  
  96.         self.resize(QSize(420,163).expandedTo(self.minimumSizeHint()))
  97.         self.clearWState(Qt.WState_Polished)
  98.  
  99.         self.connect(self.okPushButton,SIGNAL("clicked()"),self.accept)
  100.         self.connect(self.passwordLineEdit,SIGNAL("returnPressed()"),self.accept)
  101.         self.promptTextLabel.setText(prompt)
  102.         
  103.     def getPassword(self):
  104.         return str(self.passwordLineEdit.text())
  105.  
  106.     def languageChange(self):
  107.         self.setCaption(self.__tr("HP Device Manager - Enter Password"))
  108.         self.okPushButton.setText(self.__tr("OK"))
  109.  
  110.     def __tr(self,s,c = None):
  111.         return qApp.translate("PasswordDialog",s,c)
  112.         
  113.  
  114. def PasswordUI(prompt):
  115.     QApplication.restoreOverrideCursor()
  116.     
  117.     dlg = PasswordDialog(prompt, None)
  118.     
  119.     if dlg.exec_loop() == QDialog.Accepted:
  120.         return dlg.getPassword()
  121.         
  122.     QApplication.setOverrideCursor(QApplication.waitCursor)
  123.     return ""
  124.         
  125.  
  126. class DevMgr4(DevMgr4_base):
  127.     def __init__(self, hpiod_sock, hpssd_sock, 
  128.                  cleanup=None, toolbox_version='0.0',
  129.                  parent=None, name=None, fl = 0):
  130.  
  131.         DevMgr4_base.__init__(self, parent, name, fl)
  132.  
  133.         icon = QPixmap(os.path.join(prop.image_dir, 'HPmenu.png'))
  134.         self.setIcon(icon)
  135.  
  136.         log.debug("Initializing toolbox UI...")
  137.         self.cleanup = cleanup
  138.         self.hpiod_sock = hpiod_sock
  139.         self.hpssd_sock = hpssd_sock
  140.         self.toolbox_version = toolbox_version
  141.         self.cur_device_uri = user_cfg.last_used.device_uri # Device URI
  142.         self.devices = {}    # { Device_URI : device.Device(), ... }
  143.         self.device_vars = {}
  144.         self.num_devices = 0
  145.         self.cur_device = None
  146.         self.rescanning = False
  147.  
  148.         self.email_alerts = utils.to_bool(user_cfg.alerts.email_alerts, False)
  149.         self.email_to_addresses = user_cfg.alerts.email_to_addresses
  150.         self.email_from_address = user_cfg.alerts.email_from_address
  151.         self.auto_refresh = utils.to_bool(user_cfg.refresh.enable, False)
  152.  
  153.         try:
  154.             self.auto_refresh_rate = int(user_cfg.refresh.rate)
  155.         except ValueError:    
  156.             self.auto_refresh_rate = DEF_AUTO_REFRESH_RATE
  157.  
  158.         try:
  159.             self.auto_refresh_type = int(user_cfg.refresh.type)
  160.         except ValueError:
  161.             self.auto_refresh_type = 0 # refresh 1 (1=refresh all)
  162.  
  163.         cmd_print, cmd_scan, cmd_pcard, \
  164.             cmd_copy, cmd_fax, cmd_fab = utils.deviceDefaultFunctions()
  165.  
  166.         self.cmd_print = user_cfg.commands.prnt or cmd_print
  167.         self.cmd_print_int = utils.to_bool(user_cfg.commands.prnt_int, True)
  168.         
  169.         self.cmd_scan = user_cfg.commands.scan or cmd_scan
  170.         self.cmd_scan_int = utils.to_bool(user_cfg.commands.scan_int, False)
  171.         
  172.         self.cmd_pcard = user_cfg.commands.pcard or cmd_pcard
  173.         self.cmd_pcard_int = utils.to_bool(user_cfg.commands.pcard_int, False)
  174.         
  175.         self.cmd_copy = user_cfg.commands.cpy or cmd_copy
  176.         self.cmd_copy_int = utils.to_bool(user_cfg.commands.cpy_int, False)
  177.         
  178.         self.cmd_fax = user_cfg.commands.fax or cmd_fax
  179.         self.cmd_fax_int = utils.to_bool(user_cfg.commands.fax_int, False)
  180.         
  181.         self.cmd_fab = user_cfg.commands.fab or cmd_fab
  182.         self.cmd_fab_int = utils.to_bool(user_cfg.commands.fab_int, False)
  183.         
  184.         log.debug("HPLIP Version: %s" % sys_cfg.hplip.version)
  185.         
  186.         log.debug("Print command: %s" % self.cmd_print)
  187.         log.debug("Use Internal print command: %s" % self.cmd_print_int)
  188.         
  189.         log.debug("PCard command: %s" % self.cmd_pcard)
  190.         log.debug("Use internal PCard command: %s" % self.cmd_pcard_int)
  191.         
  192.         log.debug("Fax command: %s" % self.cmd_fax)
  193.         log.debug("Use internal fax command: %s" % self.cmd_fax_int)
  194.         
  195.         log.debug("FAB command: %s" % self.cmd_fab)
  196.         log.debug("Use internal FAB command: %s" % self.cmd_fab_int)
  197.         
  198.         log.debug("Copy command: %s " % self.cmd_copy)
  199.         log.debug("Use internal copy command: %s " % self.cmd_copy_int)
  200.         
  201.         log.debug("Scan command: %s" % self.cmd_scan)
  202.         log.debug("Use internal scan command: %s" % self.cmd_scan_int)
  203.         
  204.         log.debug("Email alerts: %s" % self.email_alerts)
  205.         log.debug("Email to address(es): %s" % self.email_to_addresses)
  206.         log.debug("Email from address: %s" % self.email_from_address)
  207.         log.debug("Auto refresh: %s" % self.auto_refresh)
  208.         log.debug("Auto refresh rate: %s" % self.auto_refresh_rate)
  209.         log.debug("Auto refresh type: %s" % self.auto_refresh_type)
  210.  
  211.         if not self.auto_refresh:
  212.             self.autoRefresh.toggle()
  213.  
  214.         self.InitDeviceList()
  215.  
  216.         self.InitFunctionsTab()
  217.         self.InitStatusTab()
  218.         self.InitMaintTab()
  219.         self.InitSuppliesTab()
  220.         self.InitPrintSettingsTab()
  221.         self.InitPrintJobsTab()
  222.  
  223.         self.TabIndex = { self.FunctionsTab: self.FuncList,
  224.                           self.StatusTab: self.StatusList,
  225.                           self.MaintTab: self.ToolList,
  226.                           self.SuppliesTab: self.SuppliesList,
  227.                           self.PrintSettingsTab: self.PrintSettingsList,
  228.                           self.PrintJobsTab: self.PrintJobsList,
  229.                           self.MaintTab: self.ToolList
  230.                         }
  231.                           
  232.         cups.setPasswordCallback(PasswordUI)
  233.  
  234.         QTimer.singleShot(0, self.InitialUpdate)
  235.  
  236.  
  237.     def InitialUpdate(self):
  238.         self.RescanDevices(init=True)
  239.  
  240.         self.refresh_timer = QTimer(self, "RefreshTimer")
  241.         self.connect(self.refresh_timer, SIGNAL('timeout()'), self.TimedRefresh)
  242.  
  243.         if MIN_AUTO_REFRESH_RATE <= self.auto_refresh_rate <= MAX_AUTO_REFRESH_RATE:
  244.             self.refresh_timer.start(self.auto_refresh_rate * 1000)
  245.             
  246.     def InitDeviceList(self):
  247.         self.DeviceList.setAutoArrange(False)
  248.         # Resize the splitter so that the device list starts as a single column
  249.         self.splitter2.setSizes([120, 700]) 
  250.  
  251.  
  252.     def InitFunctionsTab(self):
  253.         self.FuncList = ScrollFunctionsView(self.cmd_print, self.cmd_print_int,
  254.                                             self.cmd_scan, self.cmd_scan_int,
  255.                                             self.cmd_pcard, self.cmd_pcard_int,
  256.                                             self.cmd_fax, self.cmd_fax_int,
  257.                                             self.cmd_copy, self.cmd_copy_int,
  258.                                             self.FunctionsTab, self, "FuncView")
  259.  
  260.         self.FuncTabLayout = QGridLayout(self.FunctionsTab,1,1,11,6,"FuncTabLayout")
  261.         self.FuncTabLayout.addWidget(self.FuncList,0,0)
  262.  
  263.     def SwitchFunctionsTab(self, page='funcs'):
  264.         self.FuncTabLayout.remove(self.FuncList)
  265.         self.FuncList.hide()
  266.         
  267.         if page == 'funcs':
  268.             self.Tabs.changeTab(self.FunctionsTab,self.__tr("Functions"))
  269.             self.FuncList = ScrollFunctionsView(self.cmd_print, self.cmd_print_int,
  270.                                                 self.cmd_scan, self.cmd_scan_int,
  271.                                                 self.cmd_pcard, self.cmd_pcard_int,
  272.                                                 self.cmd_fax, self.cmd_fax_int,
  273.                                                 self.cmd_copy, self.cmd_copy_int,
  274.                                                 self.FunctionsTab, self, "FuncView")
  275.  
  276.         elif page == 'print':
  277.             self.Tabs.changeTab(self.FunctionsTab,self.__tr("Functions > Print"))
  278.             self.FuncList = ScrollPrintView(True, self.FunctionsTab, self, "PrintView")
  279.             #current_printer = self.PrintSettingsPrinterCombo.currentText()
  280.             
  281.         
  282.         elif page == 'scan':
  283.             pass
  284.             
  285.         elif page == 'copy':
  286.             pass
  287.             
  288.         elif page == 'fax':
  289.             self.Tabs.changeTab(self.FunctionsTab,self.__tr("Functions > Fax"))
  290.             self.FuncList = ScrollFaxView(True, self.FunctionsTab, self, "FaxView")
  291.             
  292.         elif page == 'pcard':
  293.             pass
  294.             
  295.         self.FuncTabLayout.addWidget(self.FuncList, 0, 0)
  296.         self.FuncList.show()
  297.         self.TabIndex[self.FunctionsTab] = self.FuncList
  298.         self.FuncList.onDeviceChange(self.cur_device)
  299.         #self.FuncList.onPrinterChange(self.current_printer)
  300.             
  301.  
  302.     def InitStatusTab(self):
  303.         StatusTabLayout = QGridLayout(self.StatusTab,1,1,11,6,"StatusTabLayout")
  304.  
  305.         self.Panel_2 = QLabel(self.StatusTab,"Panel_2")
  306.         self.Panel_2.setSizePolicy(QSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed,0,0,self.Panel_2.sizePolicy().hasHeightForWidth()))
  307.         self.Panel_2.setMinimumSize(QSize(254,40))
  308.         self.Panel_2.setMaximumSize(QSize(254,40))
  309.         self.Panel_2.setScaledContents(1)
  310.  
  311.         StatusTabLayout.addWidget(self.Panel_2,0,1)
  312.         spacer21 = QSpacerItem(151,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  313.         StatusTabLayout.addItem(spacer21,0,2)
  314.         spacer22 = QSpacerItem(101,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  315.         StatusTabLayout.addItem(spacer22,0,0)
  316.  
  317.         self.StatusList = ScrollStatusView(self.StatusTab, "statuslist")
  318.         StatusTabLayout.addMultiCellWidget(self.StatusList,1,1,0,2)
  319.  
  320.         self.warning_pix_small = QPixmap(os.path.join(prop.image_dir, "warning_small.png"))
  321.         self.error_pix_small = QPixmap(os.path.join(prop.image_dir, "error_small.png"))
  322.         self.ok_pix_small = QPixmap(os.path.join(prop.image_dir, "ok_small.png"))
  323.         self.lowink_pix_small = QPixmap(os.path.join(prop.image_dir, 'inkdrop_small.png'))
  324.         self.lowtoner_pix_small = QPixmap(os.path.join(prop.image_dir, 'toner_small.png'))
  325.         self.busy_pix_small = QPixmap(os.path.join(prop.image_dir, 'busy_small.png'))
  326.         self.lowpaper_pix_small = QPixmap(os.path.join(prop.image_dir, 'paper_small.png'))
  327.  
  328.         # pixmaps: (inkjet, laserjet)
  329.         self.SMALL_ICONS = { ERROR_STATE_CLEAR : (None, None),
  330.                               ERROR_STATE_BUSY : (self.busy_pix_small, self.busy_pix_small),
  331.                               ERROR_STATE_ERROR : (self.error_pix_small, self.error_pix_small),
  332.                               ERROR_STATE_LOW_SUPPLIES : (self.lowink_pix_small, self.lowtoner_pix_small),
  333.                               ERROR_STATE_OK : (self.ok_pix_small, self.ok_pix_small),
  334.                               ERROR_STATE_WARNING : (self.warning_pix_small, self.warning_pix_small),
  335.                               ERROR_STATE_LOW_PAPER: (self.lowpaper_pix_small, self.lowpaper_pix_small),
  336.                               ERROR_STATE_PRINTING : (self.busy_pix_small, self.busy_pix_small),   
  337.                               ERROR_STATE_SCANNING : (self.busy_pix_small, self.busy_pix_small),
  338.                               ERROR_STATE_PHOTOCARD : (self.busy_pix_small, self.busy_pix_small),
  339.                               ERROR_STATE_FAXING : (self.busy_pix_small, self.busy_pix_small),
  340.                               ERROR_STATE_COPYING : (self.busy_pix_small, self.busy_pix_small),
  341.                             }
  342.  
  343.         self.blank_lcd = os.path.join(prop.image_dir, "panel_lcd.xpm")
  344.         self.Panel_2.setPixmap(QPixmap(self.blank_lcd))
  345.  
  346.     def InitMaintTab(self): # Add Scrolling Maintenance (Tools)
  347.         self.ToolList = ScrollToolView(True, self.MaintTab, self, "ToolView")
  348.         self.MaintTabLayout = QGridLayout(self.MaintTab,1,1,11,6,"MaintTabLayout")
  349.         self.MaintTabLayout.addWidget(self.ToolList,0,0)
  350.         
  351.     def SwitchMaintTab(self, page='tools'):
  352.         self.MaintTabLayout.remove(self.ToolList)
  353.         self.ToolList.hide()
  354.         
  355.         if page == 'tools':
  356.             self.Tabs.changeTab(self.MaintTab,self.__tr("Tools"))
  357.             self.ToolList = ScrollToolView(True, self.MaintTab, self, "ToolView")
  358.  
  359.         elif page == 'device_info':
  360.             self.Tabs.changeTab(self.MaintTab,self.__tr("Tools > Device Information"))
  361.             self.ToolList = ScrollDeviceInfoView(True, self.MaintTab, self, "DeviceInfoView")
  362.             
  363.         elif page == 'printer_info':
  364.             self.Tabs.changeTab(self.MaintTab,self.__tr("Tools > Printer Information"))
  365.             self.ToolList = ScrollPrinterInfoView(True, self.MaintTab, self, "PrinterInfoView")
  366.             
  367.         elif page == 'testpage':
  368.             self.Tabs.changeTab(self.MaintTab,self.__tr("Tools > Print Test Page"))
  369.             
  370.             self.ToolList = ScrollTestpageView(True, self.MaintTab, self, "ScrollTestpageView")
  371.             
  372.         self.MaintTabLayout.addWidget(self.ToolList, 0, 0)
  373.         self.ToolList.show()
  374.         self.TabIndex[self.MaintTab] = self.ToolList
  375.         self.ToolList.onDeviceChange(self.cur_device)
  376.         
  377.  
  378.     def InitSuppliesTab(self): # Add Scrolling Supplies 
  379.         self.SuppliesList = ScrollSuppliesView(self.SuppliesTab, "SuppliesView")
  380.         SuppliesTabLayout = QGridLayout(self.SuppliesTab,1,1,11,6,"SuppliesTabLayout")
  381.         self.SuppliesList.setHScrollBarMode(QScrollView.AlwaysOff)
  382.         SuppliesTabLayout.addWidget(self.SuppliesList,0,0)    
  383.  
  384.     def InitPrintSettingsTab(self): # Add Scrolling Print Settings
  385.         PrintJobsTabLayout = QGridLayout(self.PrintSettingsTab,1,1,11,6,"PrintJobsTabLayout")
  386.  
  387.         self.PrintSettingsList = ScrollPrintSettingsView(self.PrintSettingsTab, "PrintSettingsView")
  388.         PrintJobsTabLayout.addMultiCellWidget(self.PrintSettingsList,1,1,0,5)
  389.  
  390.         self.PrintSettingsPrinterCombo = QComboBox(0,self.PrintSettingsTab,"comboBox5")
  391.         self.PrintSettingsPrinterCombo.setSizePolicy(QSizePolicy(QSizePolicy.Expanding,QSizePolicy.Fixed,0,0,
  392.             self.PrintSettingsPrinterCombo.sizePolicy().hasHeightForWidth()))
  393.  
  394.         PrintJobsTabLayout.addMultiCellWidget(self.PrintSettingsPrinterCombo,0,0,2,3)
  395.  
  396.         textLabel12 = QLabel(self.PrintSettingsTab,"textLabel12")
  397.         PrintJobsTabLayout.addWidget(textLabel12,0,1)
  398.  
  399.         textLabel12.setText(self.__tr("Printer Name:"))
  400.  
  401.         spacer34 = QSpacerItem(171,20,QSizePolicy.Preferred,QSizePolicy.Minimum)
  402.         PrintJobsTabLayout.addMultiCell(spacer34,0,0,4,5)
  403.  
  404.         spacer35 = QSpacerItem(71,20,QSizePolicy.Preferred,QSizePolicy.Minimum)
  405.         PrintJobsTabLayout.addItem(spacer35,0,0)
  406.  
  407.         self.connect(self.PrintSettingsPrinterCombo, SIGNAL("activated(const QString&)"), self.SettingsPrinterCombo_activated)
  408.  
  409.     def InitPrintJobsTab(self):
  410.         # Add Scrolling Print Jobs
  411.         PrintJobsTabLayout = QGridLayout(self.PrintJobsTab,1,1,11,6,"PrintJobsTabLayout")
  412.  
  413.         self.PrintJobsList = ScrollPrintJobView(self.PrintJobsTab, "PrintJobsView")
  414.         PrintJobsTabLayout.addMultiCellWidget(self.PrintJobsList,1,1,0,5)
  415.  
  416.         self.PrintJobPrinterCombo = QComboBox(0,self.PrintJobsTab,"comboBox5")
  417.         self.PrintJobPrinterCombo.setSizePolicy(QSizePolicy(QSizePolicy.Expanding,QSizePolicy.Fixed,0,0,
  418.             self.PrintJobPrinterCombo.sizePolicy().hasHeightForWidth()))
  419.  
  420.         PrintJobsTabLayout.addMultiCellWidget(self.PrintJobPrinterCombo,0,0,2,3)
  421.  
  422.         textLabel12 = QLabel(self.PrintJobsTab,"textLabel12")
  423.         PrintJobsTabLayout.addWidget(textLabel12,0,1)
  424.  
  425.         textLabel12.setText(self.__tr("Printer Name:"))
  426.  
  427.         spacer34 = QSpacerItem(171,20,QSizePolicy.Preferred,QSizePolicy.Minimum)
  428.         PrintJobsTabLayout.addMultiCell(spacer34,0,0,4,5)
  429.  
  430.         spacer35 = QSpacerItem(71,20,QSizePolicy.Preferred,QSizePolicy.Minimum)
  431.         PrintJobsTabLayout.addItem(spacer35,0,0)
  432.  
  433.         #StartStopPrinterButton.setText(self.__tr("Stop Printer"))
  434.  
  435.         self.connect(self.PrintJobPrinterCombo, SIGNAL("activated(const QString&)"), self.JobsPrinterCombo_activated)
  436.  
  437.     def TimedRefresh(self):
  438.         if self.auto_refresh:
  439.             log.debug("Refresh timer...")
  440.             self.CleanupChildren()
  441.  
  442.             if self.auto_refresh_type == 0:
  443.                 self.UpdateDevice()
  444.             else:
  445.                 self.RescanDevices()
  446.  
  447.     def autoRefresh_toggled(self,a0):
  448.         self.auto_refresh = bool(a0)
  449.         self.SaveConfig()
  450.  
  451.  
  452.     def closeEvent(self, event):
  453.         self.Cleanup()
  454.         event.accept()
  455.  
  456.  
  457.     def RescanDevices(self, init=False):
  458.         if not self.rescanning:
  459.             self.deviceRefreshAll.setEnabled(False)
  460.             self.DeviceListRefresh()
  461.             self.deviceRefreshAll.setEnabled(True)
  462.  
  463.             if not init:
  464.                 self.UpdateDevice()
  465.  
  466.     def ActivateDevice(self, device_uri):
  467.         log.debug(utils.bold("Activate: %s %s %s" % ("*"*20, device_uri, "*"*20)))
  468.         d = self.DeviceList.firstItem()
  469.         found = False
  470.  
  471.         while d is not None:
  472.  
  473.             if d.device_uri == device_uri:
  474.                 found = True
  475.                 self.DeviceList.setSelected(d, True)
  476.                 break
  477.  
  478.             d = d.nextItem()
  479.  
  480.         return found
  481.  
  482.  
  483.     def Cleanup(self):
  484.         self.CleanupChildren()
  485.         if self.cleanup is not None:
  486.             self.cleanup()
  487.  
  488.  
  489.     def CleanupChildren(self):
  490.         log.debug("Cleaning up child processes.")
  491.         try:
  492.             os.waitpid(-1, os.WNOHANG)
  493.         except OSError:
  494.             pass
  495.  
  496.  
  497.     def DeviceList_currentChanged(self, a0):
  498.         if not self.rescanning:
  499.             try:
  500.                 self.cur_device_uri = self.DeviceList.currentItem().device_uri
  501.                 self.cur_device = self.devices[self.cur_device_uri]
  502.                 user_cfg.last_used.device_uri = self.cur_device_uri
  503.             except AttributeError:
  504.                 pass
  505.  
  506.             self.UpdateDevice()
  507.  
  508.  
  509.     def DeviceList_rightButtonClicked(self, item, pos):
  510.         popup = QPopupMenu(self)
  511.  
  512.         if item is not None:
  513.             if self.cur_device.error_state != ERROR_STATE_ERROR:
  514.                 if self.cmd_print_int:
  515.                     popup.insertItem(self.__tr("Print >>"), self.PrintButton_clicked)
  516.                 else:
  517.                     popup.insertItem(self.__tr("Print..."), self.PrintButton_clicked)
  518.  
  519.                 if self.cur_device.scan_type:
  520.                     if self.cmd_scan_int:
  521.                         popup.insertItem(self.__tr("Scan >>"), self.ScanButton_clicked)
  522.                     else:
  523.                         popup.insertItem(self.__tr("Scan..."), self.ScanButton_clicked)
  524.  
  525.                 if self.cur_device.pcard_type:
  526.                     if self.cmd_pcard_int:
  527.                         popup.insertItem(self.__tr("Access Photo Cards >>"), self.PCardButton_clicked)
  528.                     else:
  529.                         popup.insertItem(self.__tr("Access Photo Cards..."), self.PCardButton_clicked)
  530.  
  531.                 if self.cur_device.fax_type:
  532.                     if self.cmd_fax_int:
  533.                         popup.insertItem(self.__tr("Send Fax >>"), self.SendFaxButton_clicked)
  534.                     else:
  535.                         popup.insertItem(self.__tr("Send Fax..."), self.SendFaxButton_clicked)
  536.  
  537.                 if self.cur_device.copy_type:
  538.                     if self.cmd_copy_int:
  539.                         popup.insertItem(self.__tr("Make Copies >>"), self.MakeCopiesButton_clicked)
  540.                     else:
  541.                         popup.insertItem(self.__tr("Make Copies..."), self.MakeCopiesButton_clicked)
  542.  
  543.                 popup.insertSeparator()
  544.  
  545.             if self.cur_device.device_settings_ui is not None:
  546.                 popup.insertItem(self.__tr("Device Settings..."), self.deviceSettingsButton_clicked)
  547.  
  548.             popup.insertItem(self.__tr("Refresh Device"), self.UpdateDevice)
  549.  
  550.         popup.insertItem(self.__tr("Refresh All"), self.deviceRefreshAll_activated)
  551.  
  552.         popup.popup(pos)
  553.  
  554.  
  555.     def UpdateDevice(self, check_state=True):
  556.         if self.cur_device is not None:
  557.             log.debug(utils.bold("Update: %s %s %s" % ("*"*20, self.cur_device_uri, "*"*20)))
  558.             self.setCaption(self.__tr("HP Device Manager - %1").arg(self.cur_device.model_ui))
  559.  
  560.             if not self.rescanning:
  561.                 self.statusBar().message(self.cur_device_uri)
  562.  
  563.             if self.cur_device.supported and check_state and not self.rescanning:
  564.                 QApplication.setOverrideCursor(QApplication.waitCursor)
  565.  
  566.                 try:
  567.                     try:
  568.                         self.cur_device.open()
  569.                     except Error, e:
  570.                         log.warn(e.msg)
  571.  
  572.                     if self.cur_device.device_state == DEVICE_STATE_NOT_FOUND:
  573.                         self.cur_device.error_state = ERROR_STATE_ERROR
  574.                     else:
  575.                         try:
  576.                             self.cur_device.queryDevice(quick=False, no_fwd=False, 
  577.                                 reread_cups_printers=False)
  578.  
  579.                         except Error, e:
  580.                             log.error("Query device error (%s)." % e.msg)
  581.                             self.cur_device.error_state = ERROR_STATE_ERROR
  582.  
  583.                 finally:
  584.                     self.cur_device.close()
  585.                     QApplication.restoreOverrideCursor()
  586.  
  587.                 log.debug("Device state = %d" % self.cur_device.device_state)
  588.                 log.debug("Status code = %d" % self.cur_device.status_code)
  589.                 log.debug("Error state = %d" % self.cur_device.error_state)
  590.  
  591.                 icon = self.CreatePixmap()
  592.                 self.DeviceList.currentItem().setPixmap(icon)
  593.  
  594.             if not self.rescanning: 
  595.                 self.UpdateHistory()
  596.                 self.Tabs_currentChanged(self.Tabs.currentPage())
  597.                 self.UpdatePrinterCombos()
  598.                 self.UpdatePanel()
  599.                 self.setupDevice.setEnabled(self.cur_device.device_settings_ui is not None)
  600.  
  601.     def UpdatePrinterCombos(self):
  602.         if self.cur_device is not None and \
  603.             self.cur_device.supported:
  604.  
  605.             self.PrintSettingsPrinterCombo.clear()
  606.             self.PrintJobPrinterCombo.clear()
  607.  
  608.             printers = cups.getPrinters()
  609.             
  610.             #cur_printers = []
  611.             self.cur_device.cups_printers = []
  612.             cur_device_uri_tail = self.cur_device_uri.split(':')[1]
  613.             for p in printers:
  614.                 p_tail = p.device_uri.split(':')[1]
  615.                 
  616.                 if p_tail == cur_device_uri_tail:
  617.                     #cur_printers.append(p.name)
  618.                     self.cur_device.cups_printers.append(p.name)
  619.                 
  620.             for c in self.cur_device.cups_printers:
  621.             #for c in cur_printers:
  622.                 self.PrintSettingsPrinterCombo.insertItem(c)
  623.                 self.PrintJobPrinterCombo.insertItem(c)
  624.                 
  625.             self.current_printer = str(self.PrintSettingsPrinterCombo.currentText())
  626.  
  627.     def SettingsPrinterCombo_activated(self, s):
  628.         self.current_printer = str(s)
  629.         self.PrintJobPrinterCombo.setCurrentText(self.current_printer)
  630.         return self.PrinterCombo_activated(self.current_printer)
  631.  
  632.     def JobsPrinterCombo_activated(self, s):
  633.         self.current_printer = str(s)
  634.         self.PrintSettingsPrinterCombo.setCurrentText(s)
  635.         return self.PrinterCombo_activated(self.current_printer)
  636.  
  637.     def PrinterCombo_activated(self, printer):
  638.         self.PrintJobsList.onPrinterChange(printer)
  639.         self.PrintSettingsList.onPrinterChange(printer)
  640.         self.FuncList.onPrinterChange(printer)
  641.  
  642.     def Tabs_currentChanged(self, tab):
  643.         try:
  644.             self.TabIndex[tab].onDeviceChange(self.cur_device)
  645.         except AttributeError:
  646.             self.TabIndex[tab]()
  647.  
  648.     def CreatePixmap(self, dev=None):
  649.         if dev is None:
  650.             dev = self.cur_device
  651.  
  652.         try:
  653.             pix = QPixmap(os.path.join(prop.image_dir, dev.icon))
  654.         except AttributeError:
  655.             pix = QPixmap(os.path.join(prop.image_dir, 'default_printer.png'))
  656.  
  657.         error_state = dev.error_state
  658.         icon = QPixmap(pix.width(), pix.height())
  659.         p = QPainter(icon)
  660.         p.eraseRect(0, 0, icon.width(), icon.height())
  661.         p.drawPixmap(0, 0, pix)
  662.  
  663.         try:
  664.             tech_type = dev.tech_type
  665.         except AttributeError:
  666.             tech_type = TECH_TYPE_NONE
  667.  
  668.         if error_state != ERROR_STATE_CLEAR:
  669.             if tech_type in (TECH_TYPE_COLOR_INK, TECH_TYPE_MONO_INK):
  670.                 status_icon = self.SMALL_ICONS[error_state][0] # ink
  671.             else:
  672.                 status_icon = self.SMALL_ICONS[error_state][1] # laser
  673.  
  674.             if status_icon is not None:
  675.                 p.drawPixmap(0, 0, status_icon)
  676.  
  677.         p.end()
  678.  
  679.         return icon
  680.  
  681.  
  682.     def DeviceListRefresh(self):
  683.         log.debug("Rescanning device list...")
  684.  
  685.         if not self.rescanning:
  686.             self.setCaption(self.__tr("Refreshing Device List - HP Device Manager"))
  687.             self.statusBar().message(self.__tr("Refreshing device list..."))
  688.  
  689.             self.rescanning = True
  690.             total_changes = 0
  691.             total_steps = 0
  692.  
  693.             self.cups_devices = device.getSupportedCUPSDevices()
  694.  
  695.             QApplication.setOverrideCursor(QApplication.waitCursor)
  696.  
  697.             # TODO: Use Set() when 2.3+ is ubiquitous
  698.  
  699.             for d in self.cups_devices: # adds
  700.                 if d not in self.devices:
  701.                     total_steps += 1
  702.                     total_changes += 1
  703.  
  704.             updates = []
  705.             for d in self.devices: # removes
  706.                 if d not in self.cups_devices:
  707.                     total_steps += 1
  708.                     total_changes += 1
  709.                 else:
  710.                     # Don't update current device as it will be updated at end
  711.                     if self.cur_device is not None and self.cur_device_uri != d:
  712.                         updates.append(d) # updates
  713.                         total_steps += 1
  714.  
  715.             log.debug("total changes = %d" % total_changes)
  716.  
  717.             step_num = 0
  718.             pb = None
  719.  
  720.             if total_steps:
  721.                 pb = QProgressBar(self.statusBar(), 'ProgressBar')
  722.                 pb.setTotalSteps(total_changes + total_steps)
  723.                 self.statusBar().addWidget(pb)
  724.                 pb.show()
  725.  
  726.             if total_changes:
  727.                 # Item addition (device added to CUPS)
  728.                 for d in self.cups_devices: 
  729.                     if d not in self.devices:
  730.                         qApp.processEvents()
  731.                         log.debug("adding: %s" % d)
  732.  
  733.                         pb.setProgress(step_num)
  734.                         step_num += 1
  735.                         qApp.processEvents()
  736.  
  737.                         log.debug(utils.bold("Refresh: %s %s %s" % \
  738.                             ("*"*20, d, "*"*20)))
  739.  
  740.                         try:
  741.                             dev = device.Device(d,
  742.                                                 hpiod_sock=self.hpiod_sock,
  743.                                                 hpssd_sock=self.hpssd_sock,
  744.                                                 callback=self.callback)
  745.                         except Error:
  746.                             log.error("Unexpected error in Device class.")
  747.                             log.exception()
  748.                             return
  749.  
  750.                         try:
  751.                             try:
  752.                                 dev.open()
  753.                             except Error, e:
  754.                                 log.warn(e.msg)
  755.  
  756.                             if dev.device_state == DEVICE_STATE_NOT_FOUND:
  757.                                 dev.error_state = ERROR_STATE_ERROR
  758.                             else:
  759.                                 dev.queryDevice(quick=True) #, no_fwd=True)
  760.  
  761.                         finally:
  762.                             dev.close()
  763.  
  764.                         self.CheckForDeviceSettingsUI(dev)
  765.  
  766.                         icon = self.CreatePixmap(dev)
  767.  
  768.                         IconViewItem(self.DeviceList, dev.model_ui,
  769.                                      icon, d)
  770.  
  771.                         self.devices[d] = dev
  772.  
  773.                 # Item removal (device removed from CUPS)
  774.                 for d in self.devices.keys():
  775.                     if d not in self.cups_devices:
  776.                         qApp.processEvents()
  777.                         item = self.DeviceList.firstItem()
  778.                         log.debug("removing: %s" % d)
  779.  
  780.                         pb.setProgress(step_num)
  781.                         step_num += 1
  782.                         qApp.processEvents()
  783.  
  784.                         while item is not None:
  785.                             if item.device_uri == d:
  786.                                 self.DeviceList.takeItem(item)
  787.                                 del self.devices[d]
  788.                                 break
  789.  
  790.                             item = item.nextItem()
  791.  
  792.             # Item updates
  793.             for d in updates:
  794.                 log.debug("updating: %s" % d)
  795.                 qApp.processEvents()
  796.                 dev = self.devices[d]
  797.  
  798.                 pb.setProgress(step_num)
  799.                 step_num += 1
  800.                 qApp.processEvents()
  801.  
  802.                 prev_error_state = dev.error_state
  803.  
  804.                 try:
  805.                     try:
  806.                         dev.open()
  807.                     except Error, e:
  808.                         log.warn(e.msg)
  809.  
  810.                     if dev.device_state == DEVICE_STATE_NOT_FOUND:
  811.                         dev.error_state = ERROR_STATE_ERROR
  812.                     else:
  813.                         dev.queryDevice(quick=True) #, no_fwd=True)
  814.  
  815.                 finally:
  816.                     dev.close()
  817.  
  818.                 if dev.error_state != prev_error_state:
  819.                     item = self.DeviceList.firstItem()
  820.  
  821.                     while item is not None:
  822.                         if item.device_uri == d:
  823.                             item.setPixmap(self.CreatePixmap(dev))
  824.                             break
  825.  
  826.                         item = item.nextItem()
  827.  
  828.             if pb is not None:
  829.                 pb.hide()
  830.                 self.statusBar().removeWidget(pb)
  831.                 pb = None
  832.  
  833.             if not len(self.cups_devices):
  834.                 QApplication.restoreOverrideCursor()
  835.                 self.cur_device = None
  836.                 self.deviceRescanAction.setEnabled(False)
  837.                 self.deviceRemoveAction.setEnabled(False)
  838.                 self.rescanning = False
  839.                 self.statusBar().message(self.__tr("Press F6 to refresh."))
  840.                 dlg = NoDevicesForm(self, "", True)
  841.                 dlg.show()
  842.                 return
  843.  
  844.             # Select current item
  845.             self.rescanning = False
  846.  
  847.             if self.cur_device_uri:
  848.                 item = self.DeviceList.firstItem()
  849.  
  850.                 while item is not None:
  851.                     qApp.processEvents()
  852.                     if item.device_uri == self.cur_device_uri:
  853.                         self.DeviceList.setCurrentItem(item)
  854.                         self.DeviceList.setSelected(item, True)
  855.                         break
  856.  
  857.                     item = item.nextItem()
  858.  
  859.                 else:
  860.                     self.cur_device = None
  861.                     self.cur_device_uri = ''
  862.  
  863.             if not self.cur_device_uri:
  864.                 self.cur_device_uri = self.DeviceList.firstItem().device_uri
  865.                 self.cur_device = self.devices[self.cur_device_uri]
  866.                 self.DeviceList.setCurrentItem(self.DeviceList.firstItem())
  867.  
  868.             user_cfg.last_used.device_uri = self.cur_device_uri
  869.  
  870.             self.DeviceList.adjustItems()
  871.             self.DeviceList.updateGeometry()
  872.             self.deviceRescanAction.setEnabled(True)
  873.             self.deviceRemoveAction.setEnabled(True)
  874.  
  875.             QApplication.restoreOverrideCursor()
  876.  
  877.  
  878.     def callback(self):
  879.         pass
  880.  
  881.     def CheckForDeviceSettingsUI(self, dev):
  882.         dev.device_settings_ui = None
  883.         name = '.'.join(['plugins', dev.model])
  884.         log.debug("Attempting to load plugin: %s" % name)
  885.         try:
  886.             mod = __import__(name, globals(), locals(), [])
  887.         except ImportError:
  888.             log.debug("No plugin found.")
  889.             return
  890.         else:
  891.             components = name.split('.')
  892.             for c in components[1:]:
  893.                 mod = getattr(mod, c)
  894.             log.debug("Loaded: %s" % repr(mod))
  895.             dev.device_settings_ui = mod.settingsUI
  896.  
  897.     def UpdateHistory(self):
  898.         try:
  899.             self.cur_device.hist = self.cur_device.queryHistory()
  900.         except Error:
  901.             log.error("History query failed.")
  902.             self.cur_device.last_event = None
  903.             self.cur_device.error_state = ERROR_STATE_ERROR
  904.             self.cur_device.status_code = STATUS_UNKNOWN
  905.         else:
  906.             try:
  907.                 self.cur_device.last_event = self.cur_device.hist[-1]
  908.             except IndexError:
  909.                 self.cur_device.last_event = None
  910.                 self.cur_device.error_state = ERROR_STATE_ERROR
  911.                 self.cur_device.status_code = STATUS_UNKNOWN
  912.  
  913.  
  914.     def UpdatePanel(self):
  915.         if self.cur_device is not None and \
  916.             self.cur_device.supported:
  917.  
  918.             dq = self.cur_device.dq
  919.  
  920.             if dq.get('panel', 0) == 1:
  921.                 line1 = dq.get('panel-line1', '')
  922.                 line2 = dq.get('panel-line2', '')
  923.             else:
  924.                 try:
  925.                     line1 = self.cur_device.hist[0][12]
  926.                 except IndexError:
  927.                     line1 = ''
  928.  
  929.                 line2 = ''
  930.  
  931.             pm = QPixmap(self.blank_lcd)
  932.  
  933.             p = QPainter()
  934.             p.begin(pm)
  935.             p.setPen(QColor(0, 0, 0))
  936.             p.setFont(self.font())
  937.  
  938.             x, y_line1, y_line2 = 10, 17, 33
  939.  
  940.             # TODO: Scroll long lines
  941.             p.drawText(x, y_line1, line1)
  942.             p.drawText(x, y_line2, line2)
  943.             p.end()
  944.  
  945.             self.Panel_2.setPixmap(pm)
  946.  
  947.         else:
  948.             self.Panel_2.setPixmap(QPixmap(self.blank_lcd))
  949.  
  950.  
  951.     def settingsConfigure_activated(self, tab_to_show=0):
  952.         dlg = SettingsDialog(self.hpssd_sock, self)
  953.  
  954.         dlg.autoRefreshCheckBox.setChecked(self.auto_refresh)
  955.         dlg.AutoRefreshRate.setValue(self.auto_refresh_rate) # min
  956.         dlg.refreshScopeButtonGroup.setButton(self.auto_refresh_type)
  957.         dlg.auto_refresh_type = self.auto_refresh_type
  958.  
  959.         dlg.EmailCheckBox.setChecked(self.email_alerts)
  960.         dlg.EmailAddress.setText(self.email_to_addresses)
  961.         dlg.senderLineEdit.setText(self.email_from_address)
  962.  
  963.         dlg.PrintCommand.setText(self.cmd_print)
  964.         dlg.PrintCommand.setEnabled(not self.cmd_print_int)
  965.         if self.cmd_print_int:
  966.             dlg.printButtonGroup.setButton(0)
  967.         else:
  968.             dlg.printButtonGroup.setButton(1)
  969.             
  970.         dlg.ScanCommand.setText(self.cmd_scan)
  971.         dlg.ScanCommand.setEnabled(not self.cmd_scan_int)
  972.         if self.cmd_scan_int:
  973.             dlg.scanButtonGroup.setButton(0)
  974.         else:
  975.             dlg.scanButtonGroup.setButton(1)
  976.         
  977.         dlg.AccessPCardCommand.setText(self.cmd_pcard)
  978.         dlg.AccessPCardCommand.setEnabled(not self.cmd_pcard_int)
  979.         if self.cmd_pcard_int:
  980.             dlg.pcardButtonGroup.setButton(0)
  981.         else:
  982.             dlg.pcardButtonGroup.setButton(1)
  983.  
  984.         dlg.SendFaxCommand.setText(self.cmd_fax)
  985.         dlg.SendFaxCommand.setEnabled(not self.cmd_fax_int)
  986.         if self.cmd_fax_int:
  987.             dlg.faxButtonGroup.setButton(0)
  988.         else:
  989.             dlg.faxButtonGroup.setButton(1)
  990.         
  991.         dlg.MakeCopiesCommand.setText(self.cmd_copy)
  992.         dlg.MakeCopiesCommand.setEnabled(not self.cmd_copy_int)
  993.         if self.cmd_copy_int:
  994.             dlg.copyButtonGroup.setButton(0)
  995.         else:
  996.             dlg.copyButtonGroup.setButton(1)
  997.  
  998.         dlg.TabWidget.setCurrentPage(tab_to_show)
  999.  
  1000.         if dlg.exec_loop() == QDialog.Accepted:
  1001.  
  1002.             self.cmd_print = str(dlg.PrintCommand.text())
  1003.             self.cmd_print_int = (dlg.printButtonGroup.selectedId() == 0)
  1004.             
  1005.             self.cmd_scan = str(dlg.ScanCommand.text())
  1006.             self.cmd_scan_int = (dlg.scanButtonGroup.selectedId() == 0)
  1007.             
  1008.             self.cmd_pcard = str(dlg.AccessPCardCommand.text())
  1009.             self.cmd_pcard_int = (dlg.pcardButtonGroup.selectedId() == 0)
  1010.             
  1011.             self.cmd_fax   = str(dlg.SendFaxCommand.text())
  1012.             self.cmd_fax_int = (dlg.faxButtonGroup.selectedId() == 0)
  1013.             
  1014.             self.cmd_copy  = str(dlg.MakeCopiesCommand.text())
  1015.             self.cmd_copy_int = (dlg.copyButtonGroup.selectedId() == 0)
  1016.  
  1017.             self.email_alerts = bool(dlg.EmailCheckBox.isChecked())
  1018.             self.email_to_addresses = str(dlg.EmailAddress.text())
  1019.             self.email_from_address = str(dlg.senderLineEdit.text())
  1020.  
  1021.             old_auto_refresh = self.auto_refresh
  1022.             self.auto_refresh = bool(dlg.autoRefreshCheckBox.isChecked())
  1023.             new_refresh_value = int(dlg.AutoRefreshRate.value())
  1024.             self.auto_refresh_type = dlg.auto_refresh_type
  1025.  
  1026.             if self.auto_refresh and new_refresh_value != self.auto_refresh_rate:
  1027.                 self.auto_refresh_rate = new_refresh_value
  1028.                 self.refresh_timer.changeInterval(self.auto_refresh_rate * 1000)
  1029.  
  1030.             if old_auto_refresh != self.auto_refresh:
  1031.                 self.autoRefresh.toggle()
  1032.  
  1033.             self.SetAlerts()
  1034.             self.SaveConfig()
  1035.  
  1036.         self.SwitchFunctionsTab("funcs")
  1037.         
  1038.         
  1039.     def SetAlerts(self):
  1040.         service.setAlerts(self.hpssd_sock,
  1041.                           self.email_alerts,
  1042.                           self.email_to_addresses,
  1043.                           self.email_from_address)
  1044.  
  1045.  
  1046.     def SaveConfig(self):
  1047.         user_cfg.commands.prnt = self.cmd_print
  1048.         user_cfg.commands.prnt_int = self.cmd_print_int
  1049.         
  1050.         user_cfg.commands.pcard = self.cmd_pcard
  1051.         user_cfg.commands.pcard_int = self.cmd_pcard_int
  1052.         
  1053.         user_cfg.commands.fax = self.cmd_fax
  1054.         user_cfg.commands.fax_int = self.cmd_fax_int
  1055.         
  1056.         user_cfg.commands.scan = self.cmd_scan
  1057.         user_cfg.commands.scan_int = self.cmd_scan_int
  1058.         
  1059.         user_cfg.commands.cpy = self.cmd_copy
  1060.         user_cfg.commands.cpy_int = self.cmd_copy_int
  1061.         
  1062.         user_cfg.alerts.email_to_addresses = self.email_to_addresses
  1063.         user_cfg.alerts.email_from_address = self.email_from_address
  1064.         user_cfg.alerts.email_alerts = self.email_alerts
  1065.         user_cfg.refresh.enable = self.auto_refresh
  1066.         user_cfg.refresh.rate = self.auto_refresh_rate
  1067.         user_cfg.refresh.type = self.auto_refresh_type
  1068.  
  1069.  
  1070.     def deviceRescanAction_activated(self):
  1071.         self.deviceRescanAction.setEnabled(False)
  1072.         self.UpdateDevice()
  1073.         self.deviceRescanAction.setEnabled(True)
  1074.  
  1075.     def deviceRefreshAll_activated(self):
  1076.         self.RescanDevices()
  1077.  
  1078.     def DeviceList_clicked(self,a0):
  1079.         pass
  1080.  
  1081.     def PrintButton_clicked(self):
  1082.         if self.cmd_print_int:
  1083.             self.Tabs.setCurrentPage(0)
  1084.             self.SwitchFunctionsTab("print")
  1085.         else:
  1086.             self.RunCommand(self.cmd_print)
  1087.  
  1088.     def ScanButton_clicked(self):
  1089.         if self.cmd_scan_int:
  1090.             self.Tabs.setCurrentPage(0)
  1091.             self.SwitchFunctionsTab("scan")
  1092.         else:
  1093.             self.RunCommand(self.cmd_scan)
  1094.  
  1095.     def PCardButton_clicked(self):
  1096.         if self.cur_device.pcard_type == PCARD_TYPE_MLC:
  1097.             if self.cmd_pcard_int:
  1098.                 self.Tabs.setCurrentPage(0)
  1099.                 self.SwitchFunctionsTab("pcard")
  1100.             else:
  1101.                 self.RunCommand(self.cmd_pcard)
  1102.         
  1103.         elif self.cur_device.pcard_type == PCARD_TYPE_USB_MASS_STORAGE:
  1104.             self.FailureUI(self.__tr("<p><b>Photocards on your printer are only available by mounting them as drives using USB mass storage.</b><p>Please refer to your distribution's documentation for setup and usage instructions."))
  1105.  
  1106.     def SendFaxButton_clicked(self):
  1107.         if self.cmd_fax_int:
  1108.             self.Tabs.setCurrentPage(0)
  1109.             self.SwitchFunctionsTab("fax")
  1110.         else:
  1111.             self.RunCommand(self.cmd_fax)
  1112.  
  1113.     def MakeCopiesButton_clicked(self):
  1114.         if self.cmd_copy_int:
  1115.             self.Tabs.setCurrentPage(0)
  1116.             self.SwitchFunctionsTab("copy")
  1117.         else:
  1118.             self.RunCommand(self.cmd_copy)
  1119.  
  1120.     def ConfigureFeaturesButton_clicked(self):
  1121.         self.settingsConfigure_activated(2)
  1122.  
  1123.     def RunCommand(self, cmd, macro_char='%'):
  1124.         QApplication.setOverrideCursor(QApplication.waitCursor)
  1125.  
  1126.         try:
  1127.             if len(cmd) == 0:
  1128.                 self.FailureUI(self.__tr("<p><b>Unable to run command. No command specified.</b><p>Use <pre>Configure...</pre> to specify a command to run."))
  1129.                 log.error("No command specified. Use settings to configure commands.")
  1130.             else:
  1131.                 log.debug(utils.bold("Run: %s %s (%s) %s" % ("*"*20, cmd, self.cur_device_uri, "*"*20)))
  1132.                 log.debug(cmd)
  1133.                 cmd = ''.join([self.cur_device.device_vars.get(x, x) \
  1134.                                  for x in cmd.split(macro_char)])
  1135.                 log.debug(cmd)
  1136.  
  1137.                 path = cmd.split()[0]
  1138.                 args = cmd.split()
  1139.  
  1140.                 log.debug(path)
  1141.                 log.debug(args)
  1142.  
  1143.                 self.CleanupChildren()
  1144.                 os.spawnvp(os.P_NOWAIT, path, args)
  1145.  
  1146.         finally:
  1147.             QApplication.restoreOverrideCursor()
  1148.  
  1149.     def helpAbout(self):
  1150.         dlg = AboutDlg(self)
  1151.         dlg.VersionText.setText(prop.version)
  1152.         dlg.ToolboxVersionText.setText(self.toolbox_version)
  1153.         dlg.exec_loop()
  1154.  
  1155.     def deviceSettingsButton_clicked(self):
  1156.         try:
  1157.             self.cur_device.open()
  1158.             self.cur_device.device_settings_ui(self.cur_device, self)
  1159.         finally:
  1160.             self.cur_device.close()
  1161.  
  1162.     def setupDevice_activated(self):
  1163.         try:
  1164.             self.cur_device.open()
  1165.             self.cur_device.device_settings_ui(self.cur_device, self)
  1166.         finally:
  1167.             self.cur_device.close()
  1168.         
  1169.         #self.cur_device.device_settings_ui(self.cur_device, self)
  1170.  
  1171.     def helpContents(self):
  1172.         f = "file://%s" % os.path.join(sys_cfg.dirs.doc, 'index.html')
  1173.         log.debug(f)
  1174.         utils.openURL(f)
  1175.  
  1176.     def deviceInstallAction_activated(self):
  1177.         su_sudo = None
  1178.         if utils.which('kdesu'):
  1179.             su_sudo = 'kdesu -- "%s"'
  1180.  
  1181.         elif utils.which('gksu'):
  1182.             su_sudo = 'gksu "%s"'
  1183.  
  1184.         if su_sudo is None:
  1185.             QMessageBox.critical(self,
  1186.                                 self.caption(),
  1187.                                 self.__tr("<b>Unable to find an appropriate su/sudo utility to run hp-setup.</b>"),
  1188.                                 QMessageBox.Ok,
  1189.                                 QMessageBox.NoButton,
  1190.                                 QMessageBox.NoButton)
  1191.         else:
  1192.             if utils.which('hp-setup'):
  1193.                 c = 'hp-setup -u --username=%s' % prop.username
  1194.                 cmd = su_sudo % c
  1195.             else:
  1196.                 c = 'python ./setup.py -u --username=%s' % prop.username
  1197.                 cmd = su_sudo % c
  1198.  
  1199.             log.debug(cmd)
  1200.             #status, output = utils.run(cmd, log_output=True, password_func=None, timeout=1)
  1201.             os.system(cmd)
  1202.  
  1203.             #self.cur_device_uri = user_cfg.last_used.device_uri
  1204.  
  1205.             self.RescanDevices()
  1206.  
  1207.  
  1208.     def deviceRemoveAction_activated(self):
  1209.         if self.cur_device is not None:
  1210.             x = QMessageBox.critical(self,
  1211.                                      self.caption(),
  1212.                                      "<b>Annoying Confirmation: Are you sure you want to remove this device?</b>" ,
  1213.                                       QMessageBox.Yes,
  1214.                                       QMessageBox.No | QMessageBox.Default,
  1215.                                       QMessageBox.NoButton)
  1216.             if x == QMessageBox.Yes:
  1217.                 QApplication.setOverrideCursor(QApplication.waitCursor)
  1218.                 print_uri = self.cur_device.device_uri
  1219.                 fax_uri = print_uri.replace('hp:', 'hpfax:')
  1220.     
  1221.                 log.debug(print_uri)
  1222.                 log.debug(fax_uri)
  1223.     
  1224.                 self.cups_devices = device.getSupportedCUPSDevices(['hp', 'hpfax'])
  1225.     
  1226.                 for d in self.cups_devices:
  1227.                     if d in (print_uri, fax_uri):
  1228.                         for p in self.cups_devices[d]:
  1229.                             log.debug("Removing %s" % p)
  1230.                             cups.delPrinter(p)
  1231.     
  1232.                 self.cur_device = None
  1233.                 self.cur_device_uri = ''
  1234.                 user_cfg.last_used.device_uri = ''
  1235.     
  1236.                 QApplication.restoreOverrideCursor()
  1237.     
  1238.                 self.RescanDevices()
  1239.  
  1240.  
  1241.     def FailureUI(self, error_text):
  1242.         QMessageBox.critical(self,
  1243.                              self.caption(),
  1244.                              error_text,
  1245.                               QMessageBox.Ok,
  1246.                               QMessageBox.NoButton,
  1247.                               QMessageBox.NoButton)
  1248.                               
  1249.     def WarningUI(self, msg):
  1250.         QMessageBox.warning(self,
  1251.                              self.caption(),
  1252.                              msg,
  1253.                               QMessageBox.Ok,
  1254.                               QMessageBox.NoButton,
  1255.                               QMessageBox.NoButton)
  1256.                               
  1257.  
  1258.  
  1259.                               
  1260.     def __tr(self,s,c = None):
  1261.         return qApp.translate("DevMgr4",s,c)
  1262.